﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HRM.DAL.DAO;
using HRM.DAL.Gateway;
using HRM.DAL.Report;

namespace HRM.BLL
{
    public class EmployeeManager
    {
        EmployeeGateway gateway = new EmployeeGateway();
        public int GetEmployeeID(Code empCode)
        {
            return gateway.GetEmployeeID(empCode);
        }

        public bool SaveEmployee(Employee employee)
        {
            CodeManager codeManager = new CodeManager();
            codeManager.SaveCode();
            int codeId = codeManager.GetEmpCodeId(employee.EmpCode.CodeName);
            gateway.SaveEmployee(codeId, employee);
          
            // Setting Leave status for new Employee
            int empId = gateway.GetEmployeeID(employee.EmpCode);
            LeaveStatusManager leaveStatusManager=new LeaveStatusManager();
            leaveStatusManager.SaveLeaveStatus(empId);

            return true;
        }

        public bool DeleteEmployee(Employee employee)
        {

            int id = gateway.GetEmployeeID(employee.EmpCode);
            return gateway.DeleteEmployee(id);
        }

        public bool EditEmployeeInfo(Employee employee)
        {
            CodeManager codeManager = new CodeManager();
            int codeId = codeManager.GetEmpCodeId(employee.EmpCode.CodeName);

            int id = gateway.GetEmployeeID(employee.EmpCode);
            return gateway.EditEmployee(id, codeId, employee);
        }

        public ViewEmployee SearchEmployeeByCode(Code code)
        {
            CodeManager codeManager = new CodeManager();
            int codeId = codeManager.GetEmpCodeId(code.CodeName);
            return gateway.SearchEmployeeByCode(codeId);
        }
        public List<ViewEmployee> SearchEmployeeByProject(Project project)
        {
            return gateway.SearchEmployeeByProject(project);
        }

        public List<ViewEmployee> SearchEmployeeByStatus(string status)
        {
            return gateway.SearchEmployeeByStatus(status);
        }

        public List<ViewEmployee> SearchEmployeeByCatagory(Catagory catagory)
        {
            return gateway.SearchEmployeeByCatagory(catagory);
        }

        public string GetEmployeeName(int Id)
        {
            return gateway.GetEmployeeName(Id);
        }

        public bool UpdateDesignation(Code code, int presentDesigId)
        {
            int empId = gateway.GetEmployeeID(code);
            return gateway.UpdateDesignation(empId, presentDesigId);
        }

        public bool ChangeStatus(Code code, string status)
        {
            int empId = gateway.GetEmployeeID(code);
            return gateway.ChangeStatus(empId, status);
        }
    }
}